package main

import (
	"github.com/sirupsen/logrus"
	_ "github.com/tluo-github/super-runner/commands"
	"github.com/tluo-github/super-runner/common"
	_ "github.com/tluo-github/super-runner/executors/kubernetes"
	_ "github.com/tluo-github/super-runner/executors/local"
	_ "github.com/tluo-github/super-runner/executors/docker"
	_ "github.com/tluo-github/super-runner/executors/ssh"
	"github.com/urfave/cli"
	"os"
)

func main() {
	app := cli.NewApp()
	app.Name = "super runner"
	app.Usage = "a Super Runner"
	app.Version = common.VERSION
	app.Authors = [] cli.Author{
		{
			"罗涛",
			"T-luot1@aaa.com",
		},
		{
			"俞杨烽",
			"csii_yuyf@aaa.com",
		},
	}
	app.CommandNotFound = func(context *cli.Context, command string) {
		logrus.Fatalln("Command", command, "not found.")
	}
	app.Commands = common.GetCommands()

	app.Before = func(c *cli.Context) error {

		file, error := os.OpenFile("/logs/super-runner.log", os.O_CREATE|os.O_WRONLY |os.O_APPEND, 0666)
		if error == nil {
			logrus.SetOutput(file)
		}
		logrus.SetLevel(logrus.DebugLevel)
		logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: "2006-01-02T15:04:05.999"})
		return nil
	}

	err := app.Run(os.Args)
	if err != nil {
		logrus.Fatal(err)
	}

}
